package com.suning.boot.controller;

import com.alibaba.fastjson.JSON;
import com.suning.boot.Property.GirlProperties;
import com.suning.boot.entity.User;
import com.suning.boot.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*;

@RestController
@EnableAutoConfiguration
public class HelloController {


    @Autowired
    GirlProperties girlProperties;

    @Autowired
    UserService userService;

    @RequestMapping(value = "/hello",method = RequestMethod.GET)
    String hello() {
        return girlProperties.getCupSize()+girlProperties.getAge();
    }

    @RequestMapping(value = "/index/{id}",method = RequestMethod.GET)
    Integer index(@PathVariable("id") Integer id) {
        return id;
    }

    @RequestMapping(value = "/say", method = RequestMethod.GET)
    String say(@RequestParam(value = "id",required = false,defaultValue = "100") Integer myId){
        return "Id : "+myId;
    }

//    @RequestMapping("/hello/{myName}")
//    String index(@PathVariable String myName) {
//        return myName;
//    }

    @RequestMapping("/getUser")
    User getUser(){
        User user = new User();
        user.setId(1);
        user.setName("jiangzhiwei");
        user.setAddress("jingjiang");
        user.setPhone("15961757187");
        return user;
    }

    @RequestMapping("/getFastJSON")
    String getUser2(){
        User user = new User();
        user.setId(1);
        user.setName("jiangzhiwei");
        user.setAddress("jingjiang");
        user.setPhone("15961757187");
        return JSON.toJSONString(user);
    }

    @RequestMapping("/zeroException")
    public int zeroException(){
        return 100/0;
    }

}
